﻿// //  ********************************************************************************
// //  Copyright (C) 2016 Sebastian Kenter. All rights reserved.
// // 
// //  Name    : MultiServerEngine | TypeDefs | EnumHelper.cs
// //  Created : 2016 - 02 - 18 08:36
// //  Modified: 2016 - 02 - 20 12:33
// //  ********************************************************************************

using System;
using System.ComponentModel;
using System.Reflection;

namespace TypeDefs
{
    public class EnumHelper
    {
        public static string GetEnumDescription(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes =
                (DescriptionAttribute[]) fi.GetCustomAttributes(typeof (DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
                return attributes[0].Description;
            return value.ToString();
        }
    }
}
